package com.wjk.test;

import java.util.ArrayList;
import java.util.List;

/**
 * @author : RobertWei
 * time: 2021/9/23    20:56
 * description:
 */

public class Demo {


}

class Solution{

    public boolean isPalindrome(ListNode head){

        if (head == null || head.next == null){
            return true;
        }

        //创建一个存储数据的数组
        List<Integer> nums = new ArrayList<>();

        while (head != null){

            nums.add(head.val);

            head = head.next;

        }

        for (int i = 0; i < nums.size()/2 ; i++) {
            if (!nums.get(i).equals(nums.get(nums.size() - i - 1))){
                return false;
            }
        }
        return true;
    }


}


class ListNode {

    int val;
    ListNode next;

    ListNode(){}

    ListNode(int val){
        this.val = val;
        next = null;
    }

    ListNode(int val , ListNode next){
        this.val = val;
        this.next = next;
    }

}